import Vue from 'vue'
import Router from 'vue-router'
// 使用路由
Vue.use(Router)
import approvals from './modules/approvals.js';
import departments from './modules/departments.js';
import employees from './modules/employees.js';
import setting from './modules/setting.js';
import salarys from './modules/salarys.js';
import social from './modules/social.js';
import attendances from './modules/attendances.js';
import permission from './modules/permission.js';

/* Layout */
// 导入主页布局
import Layout from '@/layout'
//路由分两种: 静态路由&动态路由

//静态路由
//不需要权限的
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'el-icon-s-home' }
    }]
  },


  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]
//动态路由
//其它需要进行权限验证的页面
export const asyncRouters = [
  departments,
  employees,
  setting,
  salarys,
  social,
  attendances,
  approvals,
  permission,
]
const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  // 注册静态路由 & 动态路由
  routes: [...constantRoutes, ...asyncRouters]
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
